﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetPartyForumTypeList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            PartyForumTypeOutParam result = new PartyForumTypeOutParam();
            PartyForumTypeInParam param = new PartyForumTypeInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as PartyForumTypeInParam; 
                 

                if (isFlag)
                {
                    param.parent_type_id = string.IsNullOrEmpty(param.parent_type_id) ? "" : param.parent_type_id;
                    param.branchID = string.IsNullOrEmpty(param.branchID) ? "" : param.branchID;

                    if (param.parent_type_id == "1")
                        param.parent_type_id = "A001";
                    else if (param.parent_type_id == "2")
                        param.parent_type_id = "C001";

                    if(param.parent_type_id == "C001")
                    {
                        result.code = "0";
                        result.desc = "支部论坛正在建设中";
                    }
                    if (param.parent_type_id == "C001" && string.IsNullOrEmpty(param.branchID))
                    { 
                        result.code = "0";
                        result.desc = "获取支部论坛类型,请提供支部ID号";
                    }
                    else
                    {
                        if (param.parent_type_id == "C001")
                        {
                            //DataSet ds = InterfaceHelper.GetPartyForumTypeBranchList(param.branchID);
                            //if (ds != null && ds.Tables[0].Rows.Count > 0)
                            //{
                            //    PartyForumType item = null;
                            //    foreach (DataRow dr in ds.Tables[0].Rows)
                            //    {
                            //        item = new PartyForumType();
                            //        item.type_id = dr["ID"].ToString();
                            //        item.type_name = dr["Title"].ToString();

                            //        if (item.type_id == param.branchID)
                            //            result.data.list.Insert(0, item);
                            //        else 
                            //            result.data.list.Add(item);
                            //    }
                            //}
                        }
                        else
                        {
                            DataSet ds = InterfaceHelper.GetPartyForumTypeListEx(param.parent_type_id, param.branchID);
                            if (ds != null && ds.Tables[0].Rows.Count > 0)
                            {
                                PartyForumType item = null;
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    item = new PartyForumType();
                                    item.type_id = dr["ID"].ToString();
                                    item.type_name = dr["Title"].ToString();
                                    result.data.list.Add(item);
                                }
                            }
                        }
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetPartyForumTypeList", SerializeHelper.JsonSerializer<PartyForumTypeInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<PartyForumTypeInParam, PartyForumTypeOutParam>();
            else
                SafeProcessRequest<PartyForumTypeInParam, PartyForumTypeOutParam>();
        }
    }

    #region 请求参数
    public class PartyForumTypeInParam
    {
        /// <summary>
        ///	父类别ID 如果为空的话，则查询第一层级类别，否则查询指定类别下的子类别
        /// </summary>
        public string parent_type_id
        { get; set; }

        /// <summary>
        /// 支部id号 如果查询支部论坛的论坛类别,需要提供
        /// </summary>
        public string branchID
        { get; set; } 
    }
    #endregion

    #region 结果参数
    public class PartyForumTypeOutParam
    {
        public PartyForumTypeOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new PartyForumTypeList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 论坛帖子分类
        /// </summary>
        public PartyForumTypeList data
        { get; set; }
    }


    public class PartyForumTypeList
    {
        public PartyForumTypeList()
        { 
            list = new List<PartyForumType>();
        }

        public List<PartyForumType> list { get; set; } 
    }

    /// <summary>
    /// 论坛帖子分类
    /// </summary>
    public class PartyForumType
    {
        /// <summary>
        ///	类型ID	
        /// </summary>
        public string type_id
        { get; set; }

        /// <summary>
        ///	类型名称	
        /// </summary>
        public string type_name
        { get; set; }
    }
    #endregion 
}